package com.wl.mapper;

import com.wl.pojo.AIChat.ChatHistory;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AIChatMapper {

    /**
     * 根据用户ID获取聊天记录
     * @param userId 用户id
     * @return 返回聊天记录列表
     */
    @Select("select * from chat_history where user_id = #{userId} order by chat_date desc")
    List<ChatHistory> getChatHistoryDatas(String userId);

    /**
     * 修改聊天记录标题
     */
    @Update("update chat_history set chat_title = #{chatTitle} where chat_history_id = #{chatHistoryId}")
    void updateChatHistoryTitle(ChatHistory chatHistory);

    /**
     * 删除聊天记录
     */
    @Delete("delete from chat_history where chat_history_id = #{chatHistoryId}")
    void deleteChatHistory(Integer chatHistoryId);

    /**
     * 保存聊天记录反立即返回
     * @param chatHistory 聊天记录信息
     * @return 返回插入的聊天记录
     */
    @Insert("insert into chat_history (chat_title, chat_date, messages, user_id) " +
            "values (#{chatTitle},#{chatDate},#{messages},#{userId})")
    @Options(useGeneratedKeys = true, keyProperty = "chatHistoryId")
    void saveChatHistory(ChatHistory chatHistory);
    // 返回插入的这条聊天记录
    @Select("select * from chat_history where chat_history_id = #{chatHistoryId}")
    ChatHistory returnSaveChatHistory(Integer chatHistoryId);

    /**
     * 更新聊天记录内容
     */
    @Update("update chat_history set messages = #{messages} where chat_history_id = #{chatHistoryId}")
    void updateChatHistoryMessages(ChatHistory chatHistory);
}
